package _17_函数式编程.Lambda._4_筛选颜色重量作为参数;

import _17_函数式编程.Lambda.Apple;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class _4_筛选颜色重量作为参数 {

    public static void main(String[] args) {
        List<Apple> appleList = Arrays.asList(
                new Apple("red",150),
                new Apple("green",234),
                new Apple("green",123)
        );

        List<Apple> result;

        result = filterApples(appleList,"green", 150);
        printApples(result);
    }

    /**
     * 根据颜色，重量筛选苹果
     * @param inventory
     * @param color
     * @return
     */
    public static List<Apple> filterApples(List<Apple> inventory, String color, int weight){
        List<Apple> result = new ArrayList<>();
        for (Apple apple : inventory){
            if(
                    color.equals(apple.getColor()) &&
                            apple.getWeight() >= weight
            ){
                result.add(apple);
            }
        }
        return result;
    }

    public static void printApples(List<Apple> inventory){
        for (Apple apple : inventory){
            System.out.println("苹果的颜色：" + apple.getColor() + "，重量：" + apple.getWeight());
        }
    }
}
